<!-- 防止用户未登录使用 -->
<?php
session_start();
if (isset($_POST['recNumber']))
    $_SESSION["recNumber"]=trim($_POST['recNumber']);
if(isset($_SESSION["recNumber"]))
    $RecNumPerPage=$_SESSION["recNumber"];
else
    $RecNumPerPage=10;
// 记录查询的关键字和查询的类型
if(isset($_GET["type"]))
    $_SESSION["type"]=$_GET["type"];
if(isset($_GET["keyword"]))
    $_SESSION["keyword"]=$_GET["keyword"];

?>
<html>
<head>
    <meta http-equiv="Content-Type"content="text/html; charset=UTF-8" />
    <title>社团信息显示</title>
</head>
<body>
<?php echo "<center><br /><a href='searchsoci.php'>返回查询页面</a></center>"; ?>
<center>点击社团编码链接可以查看社团信息</center>
<center>
    <form method="POST" action="showresult.php">
        <select name="recNumber" >
            <?php
            for($i=3;$i<=10;$i++){
                if ($i==$RecNumPerPage)
                    echo  "<option value=".$i." selected>每页显示".$i."条记录</option>";
                else
                    echo  "<option value=".$i.">每页显示".$i."条记录</option>";
            }
            ?>
        </select>
        <input type="submit" value="刷新" name="ok">
    </form>
</center>
<table width="540" border="1" align="center" cellpadding="0" cellspacing="1">
    <tr bgcolor="#0066CC">
        <td width="80" align="center"><font color="#FFFFFF"><b>编码</b></font></td>
        <td width="220" align="center"><font color="#FFFFFF"><b>社团名称</b></font></td>
        <td width="100" align="center"><font color="#FFFFFF"><b>类别</b></font></td>
        <td width="80" align="center"><font color="#FFFFFF"><b>级别</b></font></td>
        <td width="80"><font color="#FFFFFF" align="center"><b>需求人数</b></font></td>
    </tr>
    <!-- 执行查询语句，根据用户提供的关键字，查询结果 -->
    <?php
    include("../functions/db_conn.php");
    $ShowSoci_sql = "SELECT * FROM soci";

    if(isset($_SESSION["type"])&&isset($_SESSION["keyword"]))
        $ShowSoci_sql.=" where ".$_SESSION["type"]." LIKE '%".$_SESSION["keyword"]."%'";


    $ShowSociResult = mysql_query($ShowSoci_sql);
    $Sum = mysql_num_rows($ShowSociResult);
    // 分页显示
    if ($Sum>0)
    {
        if (isset($_GET['FirstRecNo']))
            $FirstRecNo=$_GET['FirstRecNo'];
        else
            $FirstRecNo=0;
        $MaxRecNo = $FirstRecNo + $RecNumPerPage;
        mysql_data_seek($ShowSociResult,$FirstRecNo);
        if ($Sum<$MaxRecNo)
            $recs=$RecNumPerPage-($MaxRecNo-$Sum);	//当前页需要显示的记录数
        else
            $recs=$RecNumPerPage;
        for($i=0;$i<$recs;$i++)
        {
            $row = mysql_fetch_array($ShowSociResult);
            if ($i%2 == 0)
                echo "<tr bgcolor='#DDDDDD'  align='center'>";
            else
                echo "<tr align='center'>";
            echo "<td width='80'><a href='showmysoci.php?SociNo=".$row['SociNo']."'>".$row['SociNo']."</a></td>";
            echo "<td width='220'>".$row['SociName']."</td>";
            echo "<td width='80'>".$row['Kind']."</td>";
            echo "<td width='80'>".$row['Level']."</td>";
            echo "<td width='80'>".$row['LimitNum']."</td>";
            echo "</tr>";
        }
    }
    ?>
</table>
<table width="400" border="0" align="center">
    <tr>
        <td align="center">
            <?
            if ($FirstRecNo>0)
                echo '<a href="showresult.php?FirstRecNo=0">第一页</a>';
            else
                echo "第一页";
            ?>
        </td>
        <td align="center">
            <?php
            if ($FirstRecNo>$RecNumPerPage-1)
                echo "<a href='showresult.php?FirstRecNo=".($FirstRecNo-$RecNumPerPage)."'>上一页</a>";
            else
                echo "上一页";
            ?>
        </td>
        <td align="center">
            <?php
            if ($Sum>$MaxRecNo)
                echo "<a href='showresult.php?FirstRecNo=".($FirstRecNo+$RecNumPerPage)."'>下一页</a>";
            else
                echo "下一页";
            ?>
        </td>
        <td align="center">
            <?php
            if ($Sum>$MaxRecNo)
            {
                $final = floor(($Sum-1)/$RecNumPerPage)*$RecNumPerPage;
                echo "<a href='showresult.php?FirstRecNo=$final'>最后一页</a>";
            }
            else
                echo "最后一页";
            ?>
        </td>
    </tr>
</table>
</center>
</body>
</html>
